#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define NUMBER_LENGTH 40

void RobustItoa(char[], int, int);
int RobustAtoi(char[], int);
int CharToInt(char);
char IntToChar(int);

int main()
{
    int a, b;
    char n_str[NUMBER_LENGTH];
    while (scanf(" %d %s %d", &a, n_str, &b) != EOF) {
        int value = RobustAtoi(n_str, a);

        char bns[NUMBER_LENGTH] = {0};
        RobustItoa(bns, value, b);

        printf("%s\n", bns);
    }
}

int RobustAtoi(char x[], int scale)
{
    int len = strlen(x), res = 0;
    for (int i = len - 1; i >= 0; i--) 
        res += pow(scale, len - i - 1) * CharToInt(x[i]);
    return res;
}

int CharToInt(char ch)
{
    if (ch >= 'a' && ch <= 'f') 
        return ch - 'a' + 10;
    if (ch >= 'A' && ch <= 'F') 
        return ch - 'A' + 10;
    if (ch >= '0' && ch <= '9')
        return ch - '0';

    return 0;
}

char IntToChar(int i) 
{
    if (i >= 0 && i <= 9)
        return i + '0';
    if (i >= 10 && i <= 16)
        return i - 10 + 'A';
    return '0';
}

void RobustItoa(char x[], int origin, int scale)
{
    int pos = 0;
    do {
        x[pos++] = IntToChar(origin % scale);
        origin /= scale;
    } while (origin != 0);

    char temp;
    for (int i = 0, j = pos - 1; i <= j; i++, j--) {
        temp = x[i];
        x[i] = x[j];
        x[j] = temp;
    }
}
